package com.itheima.demo04;

import java.io.*;
import java.nio.file.Files;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class ZipStreamDemo01 {
    public static void main(String[] args) throws IOException {
        //解压文件流

        //数据源 文件
        File dataSource = new File("E:\\Qianxun","qianxun-central-control.zip");
        //目标 文件
        File targetFile = new File("E:\\Qianxun\\XQS");
        zipFile(dataSource,targetFile);
    }




    public static void zipFile(File dataFile,File tarFile) throws IOException {

        ZipInputStream zom = new ZipInputStream(Files.newInputStream(dataFile.toPath()));
        ZipEntry entry;

        while ((entry  = zom.getNextEntry()) != null){
            if (entry.isDirectory()){
                File file = new File(tarFile,entry.toString());
                file.mkdirs();//这里需要创建多级目录
            }else {
                FileOutputStream fileOutputStream = new FileOutputStream(new File(tarFile,entry.toString()));
                int len;
                while ((len = zom.read()) != -1){
                    fileOutputStream.write(len);
                }
                fileOutputStream.close();
                zom.closeEntry();
            }
        }
        zom.close();




    }



}


